package com.tienon.message.service;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.tienon.framework.supports.InternalActionResult;
import com.tienon.message.entity.Raw_msg_item;
import com.tienon.message.mapper.Raw_msg_itemMapper;
import com.tienon.message.thread.LoadSendMsgTasks;

/**
 * 单笔接入
 * @author zn
 *
 */
@Component
public class LoadRawMsgItemService {
	@Resource
	private Raw_msg_itemMapper raw_msg_itemMapper;
	
	/**
	 * 插入发送原始表
	 * @param raw_msg_item 单笔对象
	 * 
	 */
	@Transactional
	public void insertRaw_msg_item(Raw_msg_item raw_msg_item){
		raw_msg_itemMapper.insertSelective(raw_msg_item);
	}
	
	/**
	 * 处理单笔接入信息
	 * @param raw_msg_item
	 * @return 返回插入成功或者失败
	 */
	public Object dealChannelAccess(Raw_msg_item raw_msg_item){
		validateBsn_cd(raw_msg_item);//校验业务验证码
		Raw_msg_item raw_msg_itemNew = matchLayout(raw_msg_item);//匹配layout模板
		insertRaw_msg_item(raw_msg_itemNew);//插入发送原始表
//		LoadSendMsgTasks.loadAppSendMsgTask(raw_msg_itemNew);//有错 ，应该传入发送原始表对象
		Map<String, Object> raw_msg_itemMap = new HashMap<String, Object>();
		raw_msg_itemMap.put("rawMsgItem", raw_msg_itemNew);
		return new InternalActionResult(true, "添加单笔发送表信息成功！", raw_msg_itemMap);
	}
	
	/**
	 * 校验消息业务码
	 * @return
	 */
	private void validateBsn_cd(Raw_msg_item raw_msg_item) {
		System.out.println("校验消息业务吗");
	}

	/**
	 * 匹配layout模板
	 * @return
	 */
	private Raw_msg_item matchLayout(Raw_msg_item raw_msg_item) {
		System.out.println("匹配layout模板");
		return raw_msg_item;
	}

}
